package com.iplant.ams.controller.dms.scada.conf;

import com.iplant.ams.service.DMSService;
import com.iplant.ams.service.po.dms.scada.conf.DMSDeviceParameter;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/DMSDeviceParameter")
public class DMSDeviceParameterController extends BasicController<DMSDeviceParameter> {

    public DMSDeviceParameterController() {
        super(DMSDeviceParameter.class);
    }

    @Autowired
    DMSService mDMSService;

    @GetMapping("/InitTable")
    public Object InitTable(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);


            ServiceResult<Integer> wServiceResult = mDMSService.DMS_InitDeviceTable(wBMSEmployee);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", null, wServiceResult.getResult());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), null, wServiceResult.getResult());
            }
        } catch (Exception ex) {
            log.error("Current", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }

}
